//
//  SetUpViewController.m
//  Advertisement
//
//  Created by mac on 16/3/12.
//  Copyright © 2016年 Appcoda. All rights reserved.
//

#import "SetUpViewController.h"

@interface SetUpViewController ()

@end

@implementation SetUpViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   self.title = @"设置";
    _setUpTableVidew = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH-64)];
    _setUpTableVidew.delegate = self;
    _setUpTableVidew.dataSource = self;
    //_setUpTableVidew.backgroundColor = [UIColor orangeColor];
    _setUpTableVidew.rowHeight = 70;
    
    _alertview =[[UIAlertView alloc]initWithTitle:@"消息提示" message:@"" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    
    [self.view addSubview:_setUpTableVidew];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 8;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *resuse = @"Identifer";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:resuse];
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:resuse];
    }
    NSArray *setUpArray = @[@"退出当前帐户",@"消息推送",@"意见反馈",@"合作申请",@"缓存清理",@"给个好评",@"推荐App给好友",@"关于我们"];
    cell.textLabel.text = setUpArray[indexPath.row];
    cell.textLabel.textColor = [UIColor grayColor];
    if (indexPath.row == 1) {
        UISwitch *switchButton = [[UISwitch alloc] initWithFrame:CGRectMake(50, 100, 20, 10)];
        //设置按钮开启时的颜色
        switchButton.onTintColor = BuleColor;
        [switchButton setOn:YES];
        [switchButton addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventValueChanged];
        cell.accessoryView = switchButton;
    }
    
    return cell;
}
-(void)switchAction:(id)sender
{
    UISwitch *switchButton = (UISwitch*)sender;
    BOOL isButtonOn = [switchButton isOn];
    if (isButtonOn) {
        NSLog(@"是");
    }else {
        NSLog(@"fou");
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *rowString = [NSString stringWithFormat:@"%ld",(long)indexPath.row];
    _userdefaults = [NSUserDefaults standardUserDefaults];
    [_userdefaults setValue:rowString forKey:@"indexthRow"];
    int rowNumber = rowString.intValue;
    if (rowNumber == 0) {
        _alertview.tag = 1;
        _alertview.message = @"您要退出当前用户吗";
        [_alertview show];
    }
    if (rowNumber == 1) {
        NSLog(@"消息推送");
    }if (rowNumber == 2 ||rowNumber == 3 ||rowNumber == 7) {
        SectionViewController *sectionVC = [[SectionViewController alloc]init];
        sectionVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:sectionVC animated:NO];
        
    
    }if (rowNumber == 4) {
        _alertview.tag = 2;
        _alertview.message = @"您要清理缓存吗";
        [_alertview show];
    }if (rowNumber == 5) {
        NSLog(@"555555");
    }if (rowNumber == 6) {
        NSLog(@"6666666");
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}


@end
